package com.yiyi.user.config;

import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

@Configuration
@Component
public class WxPayConfig {

    @Autowired
    private  WebchatConfig webchatConfig;

    private  volatile Config config;

    // 静态方法，用于获取配置
    @Bean
    public  synchronized Config getConfig() {
        if (config == null) {
            config = new RSAAutoCertificateConfig.Builder()
                    .merchantId(webchatConfig.merchantId)
                    .privateKeyFromPath(webchatConfig.privateKeyPath)
                    .merchantSerialNumber(webchatConfig.merchantSerialNumber)
                    .apiV3Key(webchatConfig.apiV3Key)
                    .build();
        }
        return config;
    }

}

